package 笔试题;

import java.util.Arrays;

public class lk_1410 {
    public static void main(String[] args) {
        lk_1410 m = new lk_1410();

        System.out.println(m.entityParser("and I quote: &quot;...&quot;"));
    }
    public String entityParser(String text) {
        StringBuilder sb = new StringBuilder();
        StringBuilder s = new StringBuilder();

        boolean b = false;
        for (char c:text.toCharArray()){
            if(!b && c!='&'){
                sb.append(c);
            }else if(c == '&'){
                if(s.length()>0){
                    sb.append(s);
                    s.delete(0,Integer.MAX_VALUE);
                }
                s.append(c);
                b = true;
            }else if(c == ';'){
                b = false;
                s.append(c);
                switch (s.toString()){
                    case "&quot;":
                        sb.append("\"");
                        break;
                    case "&apos;":
                        sb.append("\'");
                        break;
                    case "&amp;":
                        sb.append("&");
                        break;
                    case "&gt;":
                        sb.append(">");
                        break;
                    case "&lt;":
                        sb.append("<");
                        break;
                    case "&frasl;":
                        sb.append("/");
                        break;
                    default:
                        sb.append(s);
                        break;
                }
                s.delete(0,Integer.MAX_VALUE);
            }else {
                s.append(c);
            }
        }
        sb.append(s);
        return sb.toString();
    }

}
